package com.example.mymatch.controller;

import com.example.mymatch.model.Post;
import com.example.mymatch.service.IPostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 控制类的实现
 * 编写者：吴茂景
 */
@Api(tags = "职位")
@RestController
public class PostController {
    @Autowired
    private IPostService postService;//对某个业务服务的内容进行定义规范  编写者：吴茂景

    @ApiOperation(value = "查询所有职位信息",notes = "获取职位信息返回json字符串")
    @RequestMapping("/getStr4")
    public String getPost(){
        return "My post";
    }
    @CrossOrigin
    @ApiOperation(value = "对职位信息的添加方法")
    @GetMapping("/addPost")
    public int addPost(Post post){
        System.out.println("进入添加职位信息接口");
        return postService.insertPost(post);
    }

    @GetMapping("getAll4")
    @ApiOperation(value = "对职位信息的查询方法")
    public List<Post> getAllPost(Post post){
        System.out.println("进入查询方法");

        List<Post> listPost=postService.getAllPost(post);

        return listPost;
    }

    @PutMapping("/editPost")
    @ApiOperation(value = "对职位信息的修改方法")
    public int EditDept(@RequestBody Post post){
        System.out.println("进入职位修改方法");
        return postService.updatePost(post);
    }

    @GetMapping("/delPost")
    @ApiOperation(value = "对职位信息的删除方法")
    public int Delete(int id){
        System.out.println("进入职位删除方法");
        int returnValue=0;
        if (id!=0){
            Post post=new Post();
            post.setId(id);
            returnValue= postService.deletePost(post);
        }
        return returnValue;
    }

    @GetMapping("/getOne4")
    @ApiOperation(value = "对单条职位信息的查询方法")
    public  Post getDept(int id){
        Post post=new Post();
        System.out.println("进入职位查询方法");
        if (id!=0){
            Post post1=new Post();
            post1.setId(id);
            post=postService.getPost(post1);
            System.out.println("返回的数据集合为："+post.getPostName());
        }
        return post;
    }
}
